import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/public/ZMTabIndicator.dart';
import 'package:flutter_demo/public_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'action.dart';
import 'state.dart';

const APPBAR_SCROLL_OFFSET = 200;
List signList = [
  {'title': '第1天', 'img': 'assets/images/user_center/task_sign_jf.png'},
  {'title': '第2天', 'img': 'assets/images/user_center/task_sign_jf.png'},
  {'title': '第3天', 'img': 'assets/images/user_center/task_sign_lb.png'},
  {'title': '第4天', 'img': 'assets/images/user_center/task_sign_jf.png'},
  {'title': '第5天', 'img': 'assets/images/user_center/task_sign_jf.png'},
  {'title': '第6天', 'img': 'assets/images/user_center/task_sign_jf.png'},
  {'title': '第7天', 'img': 'assets/images/user_center/task_sign_lb.png'},
];
List gridViewList = [
  '第一天',
  '第二天',
  '第三天',
  '第四天',
  '第五天',
  '第六天',
  '第七天',
  '第一天',
  '第二天',
  '第三天',
  '第四天',
  '第五天',
  '第六天',
  '第七天',
];

Widget buildView(TaskState state, Dispatch dispatch, ViewService viewService) {
  _onScroll(offset) {
    double alpha = offset / APPBAR_SCROLL_OFFSET;
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    dispatch(TaskActionCreator.upAppBarAlpha(alpha));
  }

  return Scaffold(
    backgroundColor: Color.fromRGBO(248, 248, 248, 1),
    body: Stack(
      children: <Widget>[
        NotificationListener(
          onNotification: (scrollNotification) {
            if (scrollNotification is ScrollUpdateNotification &&
                scrollNotification.depth == 0) {
              //滚动且是列表滚动的时候
              _onScroll(scrollNotification.metrics.pixels);
            }
            return false;
          },
          child: ListView(
            padding: EdgeInsets.only(top: 0),
            children: <Widget>[
              _headView(state, dispatch, viewService),
              _taskView(state, dispatch, viewService),
              _exchangeView(state, dispatch, viewService),
              _moneyView(state, dispatch, viewService),
              _recommendView(state, dispatch, viewService),
            ],
          ),
        ),
        Opacity(
          opacity: state.appBarAlpha,
          child: Container(
            color: Colors.white,
            width: ScreenUtil.screenWidth,
            height: ScreenUtil.statusBarHeight + 44,
            padding: EdgeInsets.only(
              top: ScreenUtil.statusBarHeight + 9,
            ),
            child: Stack(
              alignment: AlignmentDirectional.center,
              children: [
                Positioned(
                  left: setWidth(16),
                  child: GestureDetector(
                    onTap: () {},
                    child: Container(
                      child: Image.asset(
                        'assets/images/public_module/public_back.png',
                        width: setWidth(22),
                        color: Colors.black,
                      ),
                    ),
                  ),
                ),
                Text(
                  '任务中心',
                  style: TextStyle(
                    fontSize: setSp(16),
                    color: Colors.black,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    ),
  );
}

///头部
Widget _headView(TaskState state, Dispatch dispatch, ViewService viewService) {
  return Container(
    decoration: BoxDecoration(
      image: DecorationImage(
          image: AssetImage('assets/images/user_center/task_head_bg.png'),
          fit: BoxFit.fitWidth,
          alignment: Alignment.topCenter),
    ),
    child: Column(
      // crossAxisAlignment:CrossAxisAlignment.start,
      children: [
        Container(
          width: ScreenUtil.screenWidth,
          margin: EdgeInsets.only(
            top: ScreenUtil.statusBarHeight + 9,
          ),
          child: Stack(
            alignment: AlignmentDirectional.center,
            children: [
              Positioned(
                left: setWidth(16),
                child: GestureDetector(
                  onTap: () {},
                  child: Container(
                    child: Image.asset(
                      'assets/images/public_module/public_back.png',
                      width: setWidth(22),
                    ),
                  ),
                ),
              ),
              Text(
                '任务中心',
                style: TextStyle(
                  fontSize: setSp(16),
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ],
          ),
        ),
        SizedBox(
          height: setHeight(22),
        ),
        Container(
          padding: EdgeInsets.only(left: setWidth(20)),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '我的积分',
                    style: TextStyle(
                      fontSize: setSp(15),
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  Container(
                    height: setWidth(56),
                    child: Row(
                      children: [
                        Text(
                          '1000000',
                          style: TextStyle(
                            fontSize: setSp(40),
                            color: Colors.white,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        SizedBox(
                          width: setWidth(4),
                        ),
                        GestureDetector(
                          onTap: () {},
                          child: Container(
                            alignment: Alignment.center,
                            width: setWidth(77),
                            height: setHeight(25),
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.all(
                                  Radius.circular(setWidth(25))),
                              border: Border.all(width: 1, color: Colors.white),
                            ),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '积分明细',
                                  style: TextStyle(
                                    fontSize: setSp(11),
                                    color: Colors.white,
                                  ),
                                ),
                                SizedBox(
                                  width: setWidth(5),
                                ),
                                Image.asset(
                                  'assets/images/user_center/task_right.png',
                                  width: setWidth(4),
                                )
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ],
          ),
        ),
        Container(
          margin:
              EdgeInsets.fromLTRB(setWidth(15), setWidth(10), setWidth(15), 0),
          padding: EdgeInsets.symmetric(
              horizontal: setWidth(15), vertical: setWidth(15)),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(setWidth(10))),
            color: Colors.white,
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    child: Text(
                      '签到领积分',
                      style: TextStyle(
                        fontSize: setSp(16),
                        color: Color.fromRGBO(47, 47, 47, 1),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  Row(
                    children: [
                      Text(
                        '签到提醒',
                        style: TextStyle(
                          fontSize: setSp(11),
                          color: Color.fromRGBO(153, 153, 153, 1),
                        ),
                      ),
                      Transform.scale(
                        scale: 0.7,
                        child: Container(
                          width: 50,
                          height: 20,
                          child: CupertinoSwitch(
                            value: state.valueSwitch,
                            onChanged: (newValue) {
                              dispatch(TaskActionCreator.upSwitch(newValue));
                            },
                            activeColor: Color.fromRGBO(255, 37, 38, 1),
                          ),
                        ),
                      ),
                    ],
                  )
                ],
              ),
              SizedBox(
                height: setWidth(3),
              ),
              Text(
                '连续签到可获得额外奖励',
                style: TextStyle(
                  fontSize: setSp(12),
                  color: Color.fromRGBO(153, 153, 153, 1),
                ),
              ),
              SizedBox(
                height: setWidth(12),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: signList
                    .asMap()
                    .map((index, value) {
                      return MapEntry(
                        index,
                        InkWell(
                          onTap: () {},
                          child: Container(
                            padding: EdgeInsets.fromLTRB(setWidth(7),
                                setWidth(7), setWidth(7), setWidth(9)),
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.all(
                                  Radius.circular(setWidth(2))),
                              color: Color.fromRGBO(247, 247, 247, 1),
                            ),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  value['title'],
                                  style: TextStyle(
                                    fontSize: 10,
                                    color: Color.fromRGBO(102, 102, 102, 1),
                                  ),
                                ),
                                SizedBox(
                                  height: setHeight(6),
                                ),
                                Image.asset(
                                  value['img'],
                                  width: setWidth(26),
                                  height: setWidth(26),
                                ),
                              ],
                            ),
                          ),
                        ),
                      );
                    })
                    .values
                    .toList(),
              ),
              SizedBox(
                height: setHeight(20),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  InkWell(
                    onTap: () {
                      _signDialog2(state, dispatch, viewService);
                    },
                    child: Container(
                      width: setWidth(190),
                      height: setHeight(40),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        gradient: LinearGradient(colors: [
                          Color.fromRGBO(255, 106, 5, 1),
                          Color.fromRGBO(255, 37, 38, 1)
                        ]),
                        borderRadius: BorderRadius.circular(setWidth(40)),
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            "立即签到+10",
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: setSp(16),
                            ),
                          ),
                          SizedBox(width: setWidth(6)),
                          Image.asset(
                            'assets/images/user_center/task_sign_im.png',
                            width: setWidth(16),
                            height: setWidth(16),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

///任务
Widget _taskView(TaskState state, Dispatch dispatch, ViewService viewService) {
  return Container(
    margin:
        EdgeInsets.symmetric(horizontal: setWidth(15), vertical: setWidth(10)),
    padding:
        EdgeInsets.symmetric(horizontal: setWidth(15), vertical: setWidth(15)),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(setWidth(10))),
      color: Colors.white,
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          child: Text(
            '签到领花币',
            style: TextStyle(
              fontSize: setSp(17),
              color: Color.fromRGBO(47, 47, 47, 1),
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        _taskItem('assets/images/user_center/task_sign_bd.png', '绑定上级', '+10',
            "绑定上级", "去绑定"),
        _taskItem('assets/images/user_center/task_sign_ph.png', '绑定手机号', '+10',
            "绑定手机号", "去绑定"),
        _taskItem('assets/images/user_center/task_sign_tbsq.png', '淘宝授权', '+10',
            "淘宝授权", "去授权"),
        SizedBox(
          height: setWidth(15),
        ),
        Container(
          child: Text(
            '每日任务',
            style: TextStyle(
              fontSize: setSp(17),
              color: Color.fromRGBO(47, 47, 47, 1),
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        _taskItem('assets/images/user_center/task_sign_mr.png', '每日签到', '+5',
            "每日登录签到即可获得积分", "去签到"),
        _taskItem('assets/images/user_center/task_sign_ll.png', '每日浏览10个商品',
            '+20', "每日浏览商品", "8/10"),
        _taskItem('assets/images/user_center/task_sign_fx.png', '每日分享3个商品',
            '+10', "分享app任意商品", "去邀请"),
        SizedBox(
          height: setWidth(5),
        ),
        GestureDetector(
          onTap: () {
            bottomSheetDialog(state, dispatch, viewService);
          },
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                '查看更多任务',
                style: TextStyle(
                  fontSize: setSp(13),
                  color: Color.fromRGBO(153, 153, 153, 1),
                ),
              ),
              SizedBox(
                width: setWidth(5),
              ),
              Image.asset(
                'assets/images/user_center/task_sign_xx.png',
                width: setWidth(10),
                height: setWidth(10),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

Widget _taskItem(
    String img, String title1, String title2, String title3, String title4) {
  return Container(
    margin: EdgeInsets.symmetric(vertical: setWidth(15)),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Image.asset(
          img,
          width: setWidth(35),
          height: setWidth(35),
        ),
        SizedBox(
          width: setWidth(10),
        ),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Flexible(
                    child: Text(
                      title1,
                      style: TextStyle(
                        color: Color.fromRGBO(47, 47, 47, 1),
                        fontSize: setWidth(15),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  Container(
                    alignment: Alignment.center,
                    child: Text(
                      "$title2",
                      style: TextStyle(
                        color: Color.fromRGBO(255, 37, 38, 1),
                        fontSize: setWidth(14),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  SizedBox(
                    width: setWidth(3),
                  ),
                  Image.asset(
                    'assets/images/user_center/task_sign_im.png',
                    width: setWidth(14),
                    height: setWidth(14),
                  ),
                ],
              ),
              SizedBox(
                height: setWidth(2),
              ),
              Text(
                title3,
                style: TextStyle(
                  fontSize: setSp(12),
                  color: Color.fromRGBO(153, 153, 153, 1),
                ),
              ),
            ],
          ),
        ),
        InkWell(
          onTap: () {},
          child: Container(
            width: setWidth(64),
            height: setWidth(27),
            alignment: Alignment.center,
            decoration: BoxDecoration(
              gradient: LinearGradient(colors: [
                Color.fromRGBO(255, 106, 5, 1),
                Color.fromRGBO(255, 37, 38, 1)
              ]),
              borderRadius: BorderRadius.circular(setWidth(27)),
            ),
            child: Text(
              title4,
              style: TextStyle(
                fontSize: setSp(13),
                color: Colors.white,
              ),
            ),
          ),
        ),
      ],
    ),
  );
}

//花币兑换
Widget _exchangeView(
    TaskState state, Dispatch dispatch, ViewService viewService) {
  return Container(
    margin: EdgeInsets.symmetric(horizontal: setWidth(15)),
    padding:
        EdgeInsets.symmetric(horizontal: setWidth(15), vertical: setWidth(15)),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(10)),
      color: Colors.white,
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
              child: Text(
                '积分兑好礼',
                style: TextStyle(
                  fontSize: setSp(16),
                  color: Color.fromRGBO(47, 47, 47, 1),
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
            GestureDetector(
              onTap: () {
                Navigator.pushNamed(viewService.context, 'integral_exchange');
              },
              child: Row(
                children: [
                  Text(
                    "更多",
                    style: TextStyle(
                      color: Color.fromRGBO(47, 47, 47, 1),
                      fontSize: setSp(12),
                    ),
                  ),
                  Image.asset(
                    'assets/images/user_center/task_sign_right.png',
                    width: setWidth(8),
                    height: setWidth(8),
                  ),
                ],
              ),
            ),
          ],
        ),
        Container(
          height: setWidth(138),
          margin: EdgeInsets.only(top: setWidth(15)),
          color: Colors.white,
          child: ListView.separated(
            scrollDirection: Axis.horizontal,
            itemCount: 50,
            separatorBuilder: (BuildContext context, int index) {
              return Container(
                width: setWidth(7),
              );
            },
            itemBuilder: (context, index) {
              return _exchangeItem(index);
            },
          ),
        ),
      ],
    ),
  );
}

Widget _exchangeItem(int index) {
  return GestureDetector(
    onTap: () {},
    child: Container(
      width: setWidth(90),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(setWidth(8)),
            child: Image.network(
              'https://img.alicdn.com/bao/uploaded/i1/389649927/O1CN016KZY2H2NCcQR8JxMw_!!389649927.jpg',
              width: setWidth(90),
              height: setWidth(90),
              fit: BoxFit.cover,
            ),
          ),
          SizedBox(
            height: setWidth(6),
          ),
          Container(
            height: setWidth(17),
            child: Text(
              '券后价，夏季必备物品',
              style: TextStyle(
                color: Color.fromRGBO(47, 47, 47, 1),
                fontSize: setSp(12),
              ),
              overflow: TextOverflow.ellipsis,
            ),
          ),
          SizedBox(
            height: setWidth(3),
          ),
          Container(
            height: setWidth(20),
            child: Row(
              children: [
                Image.asset(
                  'assets/images/user_center/task_sign_im.png',
                  width: setWidth(14),
                  height: setWidth(14),
                ),
                SizedBox(
                  width: setWidth(3),
                ),
                Expanded(
                  child: Text.rich(
                    TextSpan(
                      children: [
                        TextSpan(
                          text: "9999 ",
                          style: TextStyle(
                            color: Color.fromRGBO(255, 37, 38, 1),
                            fontSize: setSp(14),
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        TextSpan(
                          text: '￥19.8',
                          style: TextStyle(
                            color: Color.fromRGBO(177, 178, 186, 1),
                            fontSize: setSp(11),
                            decoration: TextDecoration.lineThrough,
                            decorationColor: Colors.grey,
                          ),
                        ),
                      ],
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    ),
  );
}

///边玩边赚
Widget _moneyView(TaskState state, Dispatch dispatch, ViewService viewService) {
  bool _handleScrollNotification(ScrollNotification notification) {
    final ScrollMetrics metrics = notification.metrics;
    double alignmentY = -1 + (metrics.pixels / metrics.maxScrollExtent) * 2;
    dispatch(TaskActionCreator.upAlignmentY(alignmentY));
    print('滚动组件最大滚动距离:${metrics.maxScrollExtent}');
    print('当前滚动位置:${metrics.viewportDimension}');
    return true;
  }

  return Container(
    margin:
        EdgeInsets.symmetric(horizontal: setWidth(15), vertical: setWidth(10)),
    padding: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(10)),
      color: Colors.white,
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          child: Text(
            '边玩边赚',
            style: TextStyle(
              fontSize: setSp(16),
              color: Color.fromRGBO(47, 47, 47, 1),
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        Container(
          height: setWidth(60),
          margin: EdgeInsets.only(top: 15),
          color: Colors.white,
          child: NotificationListener<ScrollNotification>(
            onNotification: _handleScrollNotification,
            child: ListView.separated(
              scrollDirection: Axis.horizontal,
              itemCount: 50,
              separatorBuilder: (BuildContext context, int index) {
                return Container(
                  width: setWidth(0.5),
                  color: Color.fromRGBO(238, 238, 238, 1),
                  alignment: Alignment.center,
                  margin:
                      EdgeInsets.only(top: setWidth(11), bottom: setWidth(11)),
                );
              },
              itemBuilder: (context, index) {
                return _moneyItem(index);
              },
            ),
          ),
        ),
        Offstage(
          offstage: false,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                width: setWidth(16),
                height: setWidth(3),
                margin: EdgeInsets.only(top: setWidth(15)),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(setWidth(3))),
                  color: Color.fromRGBO(215, 215, 215, 1),
                ),
                alignment: Alignment(state.alignmentY, 1),
                child: Container(
                  height: setWidth(3),
                  width: setWidth(13),
                  decoration: BoxDecoration(
                    borderRadius:
                        BorderRadius.all(Radius.circular(setWidth(3))),
                    color: Color.fromRGBO(255, 37, 38, 1),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

Widget _moneyItem(int index) {
  return GestureDetector(
    onTap: () {},
    child: Container(
      width: setWidth(79),
      child: Column(
        // crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Image.asset(
            'assets/images/user_center/task_sign_maony.png',
            width: setWidth(35),
            height: setWidth(35),
          ),
          SizedBox(
            height: setWidth(7),
          ),
          Text(
            '签到赚钱',
            style: TextStyle(
              color: Color.fromRGBO(47, 47, 47, 1),
              fontSize: setSp(12),
            ),
            overflow: TextOverflow.ellipsis,
          ),
        ],
      ),
    ),
  );
}

///每日推荐
Widget _recommendView(
    TaskState state, Dispatch dispatch, ViewService viewService) {
  final tabs = ['精选推荐', '3.9包邮', '6.9包邮', '9.9包邮'];
  return Container(
    margin: EdgeInsets.only(
        left: setWidth(15), right: setWidth(15), bottom: setWidth(10)),
    padding: EdgeInsets.fromLTRB(
        setWidth(15), setWidth(5), setWidth(15), setWidth(15)),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(10)),
      color: Colors.white,
    ),
    child: Column(
      children: [
        DefaultTabController(
          length: tabs.length,
          child: Container(
            margin: EdgeInsets.only(bottom: setWidth(10)),
            child: TabBar(
              isScrollable: true,
              labelColor: Color.fromRGBO(47, 47, 47, 1),
              labelStyle:
                  TextStyle(fontSize: setSp(17), fontWeight: FontWeight.bold),
              unselectedLabelColor: Color.fromRGBO(136, 136, 136, 1),
              unselectedLabelStyle: TextStyle(fontSize: setSp(14)),
              indicatorSize: TabBarIndicatorSize.label,
              indicatorColor: Color.fromRGBO(255, 37, 38, 1),
              indicator: ZMTabIndicator(
                borderSide: BorderSide(
                    width: setWidth(3), color: Color.fromRGBO(255, 37, 38, 1)),
                insets: EdgeInsets.only(bottom: setWidth(3)),
              ),
              tabs: tabs.map((e) => Tab(text: e)).toList(),
            ),
          ),
        ),
        _recommendItem(state, dispatch, viewService)
      ],
    ),
  );
}

Widget _recommendItem(
    TaskState state, Dispatch dispatch, ViewService viewService) {
  return ListView.separated(
    padding: EdgeInsets.only(top: 0),
    shrinkWrap: true,
    physics: NeverScrollableScrollPhysics(),
    itemCount: gridViewList.length,
    separatorBuilder: (BuildContext context, int index) {
      return Container(
        height: setWidth(15),
      );
    },
    itemBuilder: (BuildContext context, int index) {
      return Container(
        //height: setWidth(102),
        child: InkWell(
          onTap: () {},
          child: Row(
            children: <Widget>[
              ClipRRect(
                borderRadius: BorderRadius.circular(setWidth(8)),
                child: Image.network(
                  'https://img.alicdn.com/bao/uploaded/i1/389649927/O1CN016KZY2H2NCcQR8JxMw_!!389649927.jpg',
                  fit: BoxFit.cover,
                  width: setWidth(108),
                  height: setWidth(108),
                ),
              ),
              SizedBox(
                width: setWidth(8),
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Container(
                      child: Text.rich(
                        TextSpan(
                          children: [
                            WidgetSpan(
                              child: Container(
                                margin: EdgeInsets.only(right: setWidth(5)),
                                child: Image.asset(
                                  'assets/images/public_module/public_shop_icon_pdd.png',
                                  width: setWidth(13),
                                  height: setWidth(13),
                                ),
                              ),
                            ),
                            TextSpan(
                              text: "8个李佳崎美妆蛋葫芦海绵粉扑不吃粉气垫彩妆蛋干湿两用化妆工具",
                              style: TextStyle(
                                fontSize: setSp(13),
                                color: Color.fromRGBO(62, 61, 72, 1),
                              ),
                            ),
                          ],
                        ),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                    SizedBox(
                      height: setWidth(10),
                    ),
                    Container(
                      child: Row(
                        children: <Widget>[
                          Container(
                            alignment: Alignment.center,
                            child: Row(
                              children: [
                                Image.asset(
                                  "assets/images/public_module/public_com_l.png",
                                  height: setWidth(17),
                                ),
                                Container(
                                  height: setWidth(17),
                                  color: Color.fromRGBO(255, 37, 38, 1),
                                  alignment: Alignment.center,
                                  child: Text(
                                    "9.77元",
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: setSp(12),
                                    ),
                                  ),
                                ),
                                Image.asset(
                                  "assets/images/public_module/public_com_r.png",
                                  height: setWidth(17),
                                ),
                              ],
                            ),
                          ),
                          SizedBox(
                            width: setWidth(5),
                          ),
                          Container(
                            alignment: Alignment.center,
                            child: Row(
                              children: [
                                Image.asset(
                                  "assets/images/public_module/public_qe_l.png",
                                  height: setWidth(17),
                                ),
                                Container(
                                  height: setWidth(17),
                                  color: Color.fromRGBO(255, 237, 203, 1),
                                  alignment: Alignment.center,
                                  child: Text(
                                    "10元",
                                    style: TextStyle(
                                      color: Color.fromRGBO(169, 107, 45, 1),
                                      fontSize: setSp(11),
                                    ),
                                  ),
                                ),
                                Image.asset(
                                  "assets/images/public_module/public_qe_r.png",
                                  height: setWidth(17),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                    SizedBox(
                      height: setWidth(6),
                    ),
                    Container(
                      child: Text.rich(
                        TextSpan(children: [
                          TextSpan(
                            text: "券后",
                            style: TextStyle(
                              fontSize: setSp(12),
                              color: Color.fromRGBO(255, 37, 38, 1),
                            ),
                          ),
                          TextSpan(
                            text: "￥",
                            style: TextStyle(
                              fontSize: setSp(14),
                              fontWeight: FontWeight.bold,
                              color: Color.fromRGBO(255, 37, 38, 1),
                            ),
                          ),
                          TextSpan(
                            text: "138",
                            style: TextStyle(
                              fontSize: setSp(16),
                              fontWeight: FontWeight.bold,
                              color: Color.fromRGBO(255, 37, 38, 1),
                            ),
                          ),
                          TextSpan(
                            text: "￥148",
                            style: TextStyle(
                              fontSize: setSp(12),
                              color: Color.fromRGBO(177, 178, 186, 1),
                              decoration: TextDecoration.lineThrough,
                            ),
                          ),
                        ]),
                      ),
                    ),
                    SizedBox(
                      height: setWidth(1),
                    ),
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Container(
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: <Widget>[
                                Image.asset(
                                  "assets/images/public_module/public_shop_icon.png",
                                  width: setWidth(11),
                                ),
                                SizedBox(
                                  width: setWidth(3),
                                ),
                                Text(
                                  "卡蒂罗旗舰店",
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                    fontSize: setSp(10),
                                    color: Color.fromRGBO(119, 119, 121, 1),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Container(
                            child: Text(
                              "月销3.66万",
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                fontSize: setSp(11),
                                color: Color.fromRGBO(119, 119, 121, 1),
                              ),
                            ),
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
      );
    },
  );
}

///更多任务弹窗
void bottomSheetDialog(
    TaskState state, Dispatch dispatch, ViewService viewService) {
  showModalBottomSheet(
    context: viewService.context,
    backgroundColor: Colors.transparent,
    // isScrollControlled: true,
    builder: (BuildContext context) {
      return Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(colors: [
            Color.fromRGBO(255, 106, 5, 1),
            Color.fromRGBO(255, 37, 38, 1)
          ]),
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(setWidth(18)),
            topRight: Radius.circular(setWidth(18)),
          ),
        ),
        child: Stack(
          children: [
            Container(
              padding: EdgeInsets.only(
                left: setWidth(15),
                top: setWidth(10),
                right: setWidth(15),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          '全部任务',
                          style: TextStyle(
                            fontSize: setSp(20),
                            color: Color.fromRGBO(255, 255, 255, 1),
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        SizedBox(
                          height: setWidth(3),
                        ),
                        Text(
                          '还有10个任务待完成，完成可得5000积分00000000',
                          style: TextStyle(
                            fontSize: setSp(11),
                            color: Color.fromRGBO(255, 255, 255, 1),
                          ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ],
                    ),
                  ),
                  Image.asset(
                    'assets/images/user_center/task_more_lbtb.png',
                    height: setWidth(68),
                    fit: BoxFit.fitHeight,
                  ),
                  SizedBox(
                    width: setWidth(5),
                  ),
                  GestureDetector(
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                    child: Image.asset(
                      'assets/images/user_center/task_more_gb.png',
                      height: setWidth(18),
                      width: setWidth(18),
                    ),
                  ),
                ],
              ),
            ),
            Positioned(
              top: setWidth(67),
              bottom: 0,
              left: 0,
              right: 0,
              child: Container(
                margin: EdgeInsets.symmetric(horizontal: setWidth(15)),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(setWidth(8)),
                    topRight: Radius.circular(setWidth(8)),
                  ),
                ),
                child: CustomScrollView(
                  // physics: NeverScrollableScrollPhysics(),
                  slivers: <Widget>[
                    SliverList(
                      delegate: SliverChildListDelegate(
                        [
                          Container(
                            padding: EdgeInsets.only(
                              top: setWidth(15),
                              left: setWidth(15),
                              right: setWidth(15),
                            ),
                            child: Text(
                              '新手任务',
                              style: TextStyle(
                                fontSize: setSp(17),
                                color: Color.fromRGBO(47, 47, 47, 1),
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                    SliverList(
                      delegate: SliverChildListDelegate(
                        [
                          _taskBottomItem(
                              'assets/images/user_center/task_sign_bd.png',
                              '绑定上级',
                              '+10',
                              "绑定上级",
                              "去绑定"),
                          _taskBottomItem(
                              'assets/images/user_center/task_sign_ph.png',
                              '绑定手机号',
                              '+10',
                              "绑定手机号",
                              "去绑定"),
                          _taskBottomItem(
                              'assets/images/user_center/task_sign_tbsq.png',
                              '淘宝授权',
                              '+10',
                              "淘宝授权",
                              "去授权"),
                        ],
                      ),
                    ),
                    SliverList(
                      delegate: SliverChildListDelegate(
                        [
                          Container(
                            padding: EdgeInsets.only(
                              left: setWidth(15),
                              top: setWidth(15),
                              right: setWidth(15),
                            ),
                            child: Text(
                              '每日任务',
                              style: TextStyle(
                                fontSize: setSp(17),
                                color: Color.fromRGBO(47, 47, 47, 1),
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                    SliverList(
                      delegate: SliverChildListDelegate(
                        [
                          _taskBottomItem(
                              'assets/images/user_center/task_sign_mr.png',
                              '每日签到',
                              '+5',
                              "每日登录签到即可获得积分",
                              "去签到"),
                          _taskBottomItem(
                              'assets/images/user_center/task_sign_ll.png',
                              '每日浏览10个商品',
                              '+20',
                              "每日浏览商品",
                              "8/10"),
                          _taskBottomItem(
                              'assets/images/user_center/task_sign_fx.png',
                              '每日分享3个商品',
                              '+10',
                              "分享app任意商品",
                              "去邀请"),
                          _taskBottomItem(
                              'assets/images/user_center/task_more_yqhy.png',
                              '邀请一位好友',
                              '+5',
                              "邀请一位好友",
                              "去邀请"),
                          _taskBottomItem(
                              'assets/images/user_center/task_more_dd.png',
                              '自推／自购订单2个',
                              '+10',
                              "自退/自购订单",
                              "8/10"),
                          _taskBottomItem(
                              'assets/images/user_center/task_more_yxcd.png',
                              '下级有效出单10个',
                              '+20',
                              "下级有效出单",
                              "5/10"),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      );
    },
  );
}

Widget _taskBottomItem(
    String img, String title1, String title2, String title3, String title4) {
  return Container(
    margin:
        EdgeInsets.symmetric(vertical: setWidth(15), horizontal: setWidth(15)),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Image.asset(
          img,
          width: setWidth(35),
          height: setWidth(35),
        ),
        SizedBox(
          width: setWidth(10),
        ),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Flexible(
                    child: Text(
                      title1,
                      style: TextStyle(
                        color: Color.fromRGBO(47, 47, 47, 1),
                        fontSize: setWidth(15),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  Container(
                    alignment: Alignment.center,
                    child: Text(
                      "$title2",
                      style: TextStyle(
                        color: Color.fromRGBO(255, 37, 38, 1),
                        fontSize: setWidth(14),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  SizedBox(
                    width: setWidth(3),
                  ),
                  Image.asset(
                    'assets/images/user_center/task_sign_im.png',
                    width: setWidth(14),
                    height: setWidth(14),
                  ),
                ],
              ),
              SizedBox(
                height: setWidth(2),
              ),
              Text(
                title3,
                style: TextStyle(
                  fontSize: setSp(12),
                  color: Color.fromRGBO(153, 153, 153, 1),
                ),
              ),
            ],
          ),
        ),
        InkWell(
          onTap: () {},
          child: Container(
            width: setWidth(64),
            height: setWidth(27),
            alignment: Alignment.center,
            decoration: BoxDecoration(
              gradient: LinearGradient(colors: [
                Color.fromRGBO(255, 106, 5, 1),
                Color.fromRGBO(255, 37, 38, 1)
              ]),
              borderRadius: BorderRadius.circular(setWidth(27)),
            ),
            child: Text(
              title4,
              style: TextStyle(
                fontSize: setSp(13),
                color: Colors.white,
              ),
            ),
          ),
        ),
      ],
    ),
  );
}

///签到提醒弹窗
_signDialog1(TaskState state, Dispatch dispatch, ViewService viewService) {
  showDialog<bool>(
    context: viewService.context,
    builder: (context) {
      return Center(
        child: GestureDetector(
          onTap: () {
            Navigator.of(context).pop();
          },
          child: Container(
            height: setWidth(247),
            width: setWidth(260),
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage(
                  'assets/images/user_center/task_sign_sctx1.png',
                ),
                fit: BoxFit.fitHeight,
              ),
            ),
            child: Container(
              margin: EdgeInsets.only(top: setWidth(118)),
              child: Text(
                '+20积分',
                style: TextStyle(
                  fontSize: setSp(30),
                  color: Color.fromRGBO(255, 37, 38, 1),
                  fontWeight: FontWeight.bold,
                  decoration: TextDecoration.none,
                ),
                textAlign: TextAlign.center,
              ),
            ),
          ),
        ),
      );
    },
  );
}

_signDialog2(TaskState state, Dispatch dispatch, ViewService viewService) {
  showDialog<bool>(
    ///Dialog不能使用InkWell
    context: viewService.context,
    builder: (context) {
      return Center(
        child: Container(
          height: setWidth(310),
          width: setWidth(260),
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage(
                'assets/images/user_center/task_sign_sctx2.png',
              ),
              fit: BoxFit.fitHeight,
            ),
          ),
          child: Column(
            children: [
              Container(
                height: setWidth(30),
                margin: EdgeInsets.only(top: setWidth(154)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Image.asset(
                      'assets/images/user_center/task_sign_im.png',
                      width: setWidth(22),
                      height: setWidth(22),
                    ),
                    SizedBox(
                      width: setWidth(5),
                    ),
                    Text(
                      "+20",
                      style: TextStyle(
                        color: Color.fromRGBO(255, 37, 38, 1),
                        fontSize: setSp(22),
                        fontWeight: FontWeight.bold,
                        decoration: TextDecoration.none,
                      ),
                    ),
                    SizedBox(
                      width: setWidth(2),
                    ),
                    Text(
                      '积分',
                      style: TextStyle(
                        color: Color.fromRGBO(255, 37, 38, 1),
                        fontSize: setSp(16),
                        fontWeight: FontWeight.bold,
                        decoration: TextDecoration.none,
                      ),
                    ),
                  ],
                ),
              ),
              SizedBox(
                height: setWidth(24),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  GestureDetector(
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                    child: Container(
                      width: setWidth(212),
                      height: setHeight(41),
                      decoration: BoxDecoration(
                        gradient: LinearGradient(colors: [
                          Color.fromRGBO(255, 106, 5, 1),
                          Color.fromRGBO(255, 37, 38, 1)
                        ]),
                        borderRadius: BorderRadius.circular(setWidth(41)),
                        boxShadow: [
                          BoxShadow(
                            offset: Offset(0.0, 2),
                            spreadRadius: 1, //阴影浓度
                            color: Color.fromRGBO(233, 31, 0, 1), //阴影颜色
                          ),
                        ],
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Image.asset(
                            'assets/images/user_center/task_sign_video.png',
                            width: setWidth(16),
                            height: setWidth(16),
                          ),
                          SizedBox(width: setWidth(5)),
                          Text(
                            "看视频，再领50积分",
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: setSp(15),
                              fontWeight: FontWeight.bold,
                              decoration: TextDecoration.none,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: setWidth(20),
              ),
              GestureDetector(
                onTap: () {
                  Navigator.of(context).pop();
                },
                child: Container(
                  height: setWidth(21),
                  child: Text('知道了',
                      style: TextStyle(
                        fontSize: setSp(15),
                        color: Color.fromRGBO(150, 150, 150, 1),
                        fontWeight: FontWeight.bold,
                        decoration: TextDecoration.none,
                      ),
                      textAlign: TextAlign.center),
                ),
              ),
            ],
          ),
        ),
      );
    },
  );
}
